﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace DataAccess.Operate
{
    public class DA_Fin02_Inherit : SqlInteractionBase
    {
        private DataSet ExeSQL(string sql)
        {
            SqlCommand cmdToExecute = new SqlCommand();
            SqlDataAdapter adapter = new SqlDataAdapter(cmdToExecute);
            DataSet ds = new DataSet();

            cmdToExecute.CommandText = sql;
            cmdToExecute.CommandType = CommandType.Text;

            try
            {
                cmdToExecute.Connection = _mainConnection;
                if (_mainConnectionIsCreatedLocal)
                {
                    _mainConnection.Open();
                }
                else
                {
                    if (_mainConnectionProvider.IsTransactionPending)
                    {
                        cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
                    }
                }

                adapter.Fill(ds);

            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
            finally
            {
                if (_mainConnectionIsCreatedLocal)
                {
                    _mainConnection.Close();
                }

                cmdToExecute.Dispose();

                adapter.Dispose();
            }

            return ds;
        }

        /// <summary>
        /// 在人事系统中模糊查询一个项目部的楼盘名
        /// ID,Name,Code,[CreateTime],[EndTime],[StatusID]
        /// </summary>
        /// <param name="depName"></param>
        /// <returns></returns>
        public DataSet GetProjectDep(string depName)
        {
            string sql = "pr_Fin02_GetProjectDep '" + depName + "'";
            DataSet ds = ExeSQL(sql);
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                return ds;
            }
            return null;
        }
        /// <summary>
        /// 获取人员的基本资料
        /// </summary>
        /// <param name="key">工号或者姓名</param>
        /// <returns></returns>
        public DataSet GetEmployeeDetail(string key)
        {
            string sql = "pr_Fin02_GetEmplyeeDetail '" + key + "'";
            DataSet ds = ExeSQL(sql);
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                return ds;
            }
            return null;
        }
    }
}
